"use strict";BX.namespace("BX.Rest.Markeplace.Category");BX.Rest.Markeplace.Category={init:function(t){this.signedParameters=t.signedParameters||{};this.filterId=t.filterId;this.leftMenuItems=BX.findChildren(BX("mp-left-menu"),{attribute:{"bx-role":"mp-left-menu-item"}},true);if(BX("mp-top-menu")){var e=BX.findChildren(BX("mp-top-menu"),{tagName:"A"},true),i;for(i=0;i<=e.length;i++){e[i].href=BX.util.add_url_param(e[i].href,{IFRAME:"Y"})}}this.initEvents();BX.Rest.Markeplace.Category.Page=this},initEvents:function(){BX.addCustomEvent("BX.Main.Filter:apply",this.onApplyFilter.bind(this));BX.addCustomEvent("BX.Main.Filter:clickMPMenu",this.clickMPMenu.bind(this));BX.addCustomEvent("BX.Main.Filter:clickMPAllLink",this.clickMPAllLink.bind(this))},clickMPAllLink:function(t){var e=BX.Main.filterManager.getById(this.filterId);if(!(e instanceof BX.Main.Filter)){return}var i=t.getAttribute("data-role");var s=e.getApi();if(i==="sale-out"){s.setFields({SALE_OUT:"Y"})}s.apply()},clickMPMenu:function(t){var e=BX.Main.filterManager.getById(this.filterId);if(!(e instanceof BX.Main.Filter)){return}var i=t.getAttribute("bx-mp-left-menu-item");var s=e.getApi();s.setFields({CATEGORY:i});e.__marketplaceFilter={filterMode:t.getAttribute("bx-filter-mode"),filterValue:t.getAttribute("bx-filter-value")};s.apply()},onApplyFilter:function(t,e,i,s,a){if(t!==this.filterId){return}if(this.leftMenuItems&&this.leftMenuItems.length>0){var r,n=i.getFilterFieldsValues()["CATEGORY"],l;for(l=0;l<this.leftMenuItems.length;l++){r=this.leftMenuItems[l];if(r.getAttribute("bx-mp-left-menu-item")!=n)BX.removeClass(r.parentNode,"ui-sidepanel-menu-active");else if(!BX.hasClass(r.parentNode,"ui-sidepanel-menu-active"))BX.addClass(r.parentNode,"ui-sidepanel-menu-active")}}a.autoResolve=false;this.reloadPage(i.__marketplaceFilter,s);delete i.__marketplaceFilter},reloadPage:function(t,e){var i=new BX.Loader({target:BX("mp-category-block"),offset:{top:"150px"}});i.show();BX.ajax.runComponentAction("bitrix:rest.marketplace.category","getPage",{mode:"class",data:t,signedParameters:this.signedParameters}).then(function(t){var s=BX.processHTML(t.data,false);BX("mp-category-block").innerHTML=s.HTML;setTimeout(BX.ajax.processScripts,500,s.SCRIPT);i.hide();if(e){e.fulfill()}},function(){i.hide();if(e){e.reject()}})}};BX.Rest.Markeplace.Category.Items={init:function(t){this.pageCount=Number(t.pageCount);this.currentPageNumber=Number(t.currentPageNumber);this.filter=t.filter||{};if(BX.type.isDomNode(BX("mp-more-button"))){BX.bind(BX("mp-more-button"),"click",function(){this.loadPage()}.bind(this))}},loadPage:function(){if(this.pageCount<=this.currentPageNumber){return}BX.addClass(BX("mp-more-button"),"ui-btn-clock");BX.ajax.runComponentAction("bitrix:rest.marketplace.category","getNextPage",{mode:"class",data:this.filter,navigation:{page:++this.currentPageNumber},signedParameters:BX.Rest.Markeplace.Category.Page.signedParameters}).then(function(t){for(var e in t.data){if(t.data.hasOwnProperty(e)){window.gridTile.appendItem(t.data[e])}}BX.removeClass(BX("mp-more-button"),"ui-btn-clock");if(this.pageCount===this.currentPageNumber){BX.remove(BX("mp-more-button"))}}.bind(this))}};BX.namespace("BX.Rest.Marketplace.TileGrid");BX.Rest.Marketplace.TileGrid.Item=function(t){BX.TileGrid.Item.apply(this,arguments);this.title=t.NAME;this.developer=t.PARTNER_NAME;this.shortDesc=t.SHORT_DESC;this.secondaryDesc=t.SECONDARY_DESC;this.image=t.ICON;this.onclick=t.ONCLICK;this.feedback=t.FEEDBACK==="Y";this.layout={container:null,secondaryDesc:null,image:null,labels:null,title:null,clipTitle:null,company:null,controls:null,buttonAction:null,price:null,feedback:null};this.currency=t.currency;this.period=t.period;this.payment=t.PRICE;this.rate=t.rate;this.action=BX.message("MARKETPLACE_SHOW_APP");this.installed=t.INSTALLED==="Y";this.url=t.URL;this.promo=t.PROMO==="Y";this.labels=t.LABELS;this.recommended=t.recommended;this.top=t.top};BX.Rest.Marketplace.TileGrid.Item.prototype={__proto__:BX.TileGrid.Item.prototype,constructor:BX.TileGrid.Item,getContent:function(){if(this.layout.container)return this.layout.container;if(this.feedback){this.getFeedbackContent()}else{this.getApplicationContent()}return this.layout.container},getApplicationContent:function(){this.layout.container=BX.create("div",{props:{className:"mp-item"},children:[this.getLabels(),this.getImage(),BX.create("div",{props:{className:"mp-item-content"},children:[this.getTitle(),this.getDesc(),this.getControls()]}),this.getStatus()]})},getFeedbackContent:function(){this.layout.container=BX.create("div",{props:{className:"mp-item mp-fb-item"},children:[BX.create("div",{props:{className:"mp-item-fb-content"},children:[this.getTitle(),this.getDesc(),this.getSecondaryDesc()]}),BX.create("div",{props:{className:"mp-item-aside"},children:[this.getImage(),this.getControls()]})]})},getStatus:function(){if(this.layout.status)return this.layout.status;this.layout.status=BX.create("div",{props:{className:"mp-item-status"},children:[this.getStatusPromo(),this.getStatusInstalled(),this.getStatusTop()]});return this.layout.status},getStatusInstalled:function(){if(!this.installed)return;return BX.create("div",{props:{className:"mp-item-status-item mp-item-status-item-installed"},text:BX.message("MARKETPLACE_INSTALLED").toUpperCase()})},getStatusPromo:function(){if(!this.promo)return;return BX.create("div",{props:{className:"mp-item-status-item mp-item-status-item-sale"},text:BX.message("MARKETPLACE_SALE").toUpperCase()})},getStatusRecommended:function(){if(!this.recommended)return;return BX.create("div",{props:{className:"mp-item-status-item mp-item-status-item-recommended"},text:"Recommended"})},getStatusTop:function(){if(!this.top)return;return BX.create("div",{props:{className:"mp-item-status-item mp-item-status-item-top"}})},getImage:function(){if(this.layout.image)return this.layout.image;this.layout.image=BX.create("div",{props:{className:"mp-item-image"},style:{backgroundImage:this.image?'url("'+this.image+'")':null}});if(!this.layout.image.hasAttribute("style"))this.layout.image.style.backgroundSize="auto";return this.layout.image},getLabels:function(){if(this.layout.labels!==null)return this.layout.labels;this.layout.labels="";if(BX.type.isArray(this.labels)){var t,e,i=[],s;for(e=0;e<Math.min(this.labels.length,5);e++){t=this.labels[e];t["COLOR"]=BX.type.isNotEmptyString(t["COLOR"])?t["COLOR"]:"";i.push(BX.create("div",{props:{className:"mp-badge-ribbon-box"+(t["COLOR"]!==""&&t["COLOR"].substring(0,1)!=="#"?" mp-badge-ribbon-box-"+t["COLOR"]:"")},children:[BX.create("span",{props:{className:"mp-badge-ribbon-item"},style:t["COLOR"].substring(0,1)==="#"?{backgroundColor:t["COLOR"]}:{},children:[BX.create("textNode",{text:t["TEXT"]}),BX.create("span",{props:{className:"mp-badge-ribbon-item-after"},style:t["COLOR"].substring(0,1)==="#"?{borderColor:[t["COLOR"],"transparent",t["COLOR"],t["COLOR"]].join(" ")}:{}})]})]}))}if(i.length>0){this.layout.labels=BX.create("div",{props:{className:"mp-badge-ribbon-wrap"},children:i})}}return this.layout.labels},getClickEvent:function(){if(!!this.onclick&&this.onclick!==""){return new Function("",this.onclick)}else{return BX.delegate(function(){BX.SidePanel.Instance.open(this.url)},this)}},getTitle:function(){if(this.layout.title){return this.layout.title}this.layout.title=BX.create("div",{props:{className:"mp-item-title"},children:[this.layout.clipTitle=BX.create("span",{text:this.title})],events:{click:this.getClickEvent()}});return this.layout.title},getDesc:function(){if(this.layout.desc)return this.layout.desc;this.layout.desc=BX.create("div",{props:{className:"mp-item-developer"+(this.hasSecondDesc()?"":" mp-item-developer-full")},text:this.shortDesc?this.shortDesc:this.developer});return this.layout.desc},hasSecondDesc:function(){return BX.type.isString(this.secondaryDesc)&&this.secondaryDesc!==""},getSecondaryDesc:function(){if(this.layout.secondaryDesc)return this.layout.secondaryDesc;if(this.hasSecondDesc()){this.layout.secondaryDesc=BX.create("div",{props:{className:"mp-item-desc-box"},children:[BX.create("div",{props:{className:"mp-item-desc"},text:this.secondaryDesc}),BX.create("div",{props:{className:"mp-item-desc-icon"}})]})}return this.layout.secondaryDesc},getControls:function(){if(this.layout.controls)return this.layout.controls;var t=null;if(this.currency)t=this.currency+"/"+this.period;this.layout.controls=BX.create("div",{props:{className:"mp-item-controls"},children:[this.layout.buttonAction=BX.create("div",{props:{className:"ui-btn ui-btn-xs ui-btn-secondary ui-btn-round"},text:this.action,events:{click:this.getClickEvent()}}),this.layout.price=BX.create("div",{props:{className:"mp-item-controls-rate"},children:[BX.create("span",{text:this.payment}),BX.create("span",{props:{className:"mp-item-controls-rate-currency"},html:t})]})]});return this.layout.controls},afterRender:function(){this.clipTitle()},clipTitle:function(){for(var t=this.layout.title.offsetHeight,e=0;t<this.layout.clipTitle.offsetHeight;e++){e++;this.layout.clipTitle.innerHTML=this.title.slice(0,-e)+"..."}}};
//# sourceMappingURL=script.map.js